﻿using UnityEngine;
using System.Collections;
namespace Room
{
    public class RCUINormalNPC : RCUIPlayer
    {
        public RCUINormalNPC(RoomCharactor owner)
            :base(owner)
        {
            type = UIType.NormalNPC;
        }

        public string npcName;
        public string pageName;
        public string pageOption;
        public int pageLevel;
        public string bubbleText;

        public void Init(string npcName,string pageName, string pageOption, int pageLevel,string bubbleText)
        {
            base.Init(npcName);
            this.npcName = npcName;
            this.pageName = pageName;
            this.pageOption = pageOption;
            this.pageLevel = pageLevel;
            this.bubbleText = bubbleText;
        }

        public override void DoStart()
        {
            base.DoStart();

            CreateBoxCollider();
        }
        public override void DoStop()
        {
            base.DoStop();
        }

        protected override void OnClick()
        {
            owner.charactorManager.room.uiFuncs += OpenPage;
        }
         
        private void OpenPage()
        {
            if(StaticData.playerData.level>=pageLevel)
            {
                if(!string.IsNullOrEmpty(pageName))
                {
                    UI.PageManager.Instance.OpenPage(pageName, pageOption);
                }
            }
            else
            {
                if(!string.IsNullOrEmpty(bubbleText))
                {
                    ShowBubble(string.Format(bubbleText, pageLevel));
                }
            }
            DataMessageTool.AddMessage(DataMessage.NPC_CLICK, owner);
        }
    }

}

